package com.personal.service.impl;

import com.personal.dao.ContactDao;
import com.personal.domain.Contact;
import com.personal.service.ContactService;
import com.personal.domain.obtain.KeyValue;
import com.personal.util.partDisplay.ContactPart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @projectName: smartCommunity_springboot
 * @package: com.personal.service.impl
 * @className: ContactServiceImpl
 * @author: bong~
 * @description: TODO
 * @date: 2023/8/10 14:40
 * @version: 1.0
 */

@Service
public class ContactServiceImpl implements ContactService {

    @Autowired
    private ContactDao contactDao;

    @Override
    public List<Contact> selectAll() {
        return contactDao.selectAll();
    }

    @Override
    public List<ContactPart> selectPartAll() {
        return contactDao.selectPartAll();
    }

    @Override
    public List<ContactPart> selectPartByKey(int enterpriseId) {
        return contactDao.selectPartByKey(enterpriseId);
    }

    @Override
    public List<KeyValue> selectIdAndNameAll() {
        return contactDao.selectIdAndNameAll();
    }

    @Override
    public boolean add(Contact contact) {
        int flag= contactDao.add(contact);
        if(flag>0)
            return true;
        return false;
    }

    @Override
    public Contact getUpdateData(int id) {
        return contactDao.getUpdateData(id);
    }

    @Override
    public boolean update(Contact contact) {
        int flag=contactDao.update(contact);
        if(flag>0)
            return true;
        return false;
    }

    @Override
    public boolean delete(List<Integer> ids) {
        for(int id:ids){
            int flag=contactDao.delete(id);
            if(flag<0)
                return false;
        }
        return true;
    }
}
